//
//  BSKNoteTableViewCell.m
//  MicroMemory
//
//  Created by rimi on 16/7/8.
//  Copyright © 2016年 BlueSky. All rights reserved.
//

#import "BSKNoteTableViewCell.h"
#import "UIView+SDAutoLayout.h"
#import "BSKNote.h"
#import "BSKWeatherPicker.h"
@interface BSKNoteTableViewCell ()

@property(nonatomic,strong) UILabel * titleLabel;
@property(nonatomic,strong) UILabel * timeLabel;
@property(nonatomic,strong) UILabel * contentLabel;
@property(nonatomic,strong) UILabel * addressLabel;
@property(nonatomic,strong) UIImageView * weatherImageView;
@property(nonatomic,strong) UIVisualEffectView * textContentView;
@property(nonatomic,copy) void(^longpressCallback)(UITableViewCell * cell);
@end

@implementation BSKNoteTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier longpressCallBack:(void(^)(UITableViewCell * cell))callback
{
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		_longpressCallback = callback;
		[self initCell];
	}
	return self;
}

-(void)setCelWithNote:(BSKNote *)note{
	_titleLabel.text = note.title;
	NSArray * array =[note.date componentsSeparatedByString:@"/"];
	_timeLabel.text =[NSString stringWithFormat:@"%@/%@",array[1],array[2]];
	_addressLabel.text = note.address;
	_contentLabel.text = note.subcontent;
	_weatherImageView.image = [UIImage imageNamed:[BSKWeatherPicker getWeatherImageNameWithType:note.weatherType]];
}

-(void)initCell{
	UILongPressGestureRecognizer * longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longpress:)];
	[self addGestureRecognizer:longpress];
	self.backgroundColor = [UIColor clearColor];
	_titleLabel = [[UILabel alloc]init];
	_timeLabel = [[UILabel alloc]init];
	_contentLabel = [[UILabel alloc]init];
	_addressLabel = [[UILabel alloc]init];
	_weatherImageView = [[UIImageView alloc]init];
	
	UIBlurEffect * efect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
	_textContentView = [[UIVisualEffectView alloc]initWithEffect:efect];
	UIView * pointView = [[UIView alloc]init];
	[self addSubview:_timeLabel];
	[self addSubview:pointView];
	[self addSubview:_textContentView];
	_textContentView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
	_textContentView.layer.borderColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.3].CGColor;
	_textContentView.layer.borderWidth = 1;
	
	[_textContentView addSubview:_titleLabel];
	[_textContentView addSubview:_addressLabel];
	[_textContentView addSubview:_weatherImageView];
	[_textContentView addSubview:_contentLabel];
	
	
	pointView.sd_layout
	.widthIs(10)
	.heightIs(10)
	.centerXIs(55)
	.centerYEqualToView(self);
	pointView.layer.cornerRadius = 5;
	pointView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
	pointView.layer.shadowColor = [UIColor blackColor].CGColor;
	pointView.layer.shadowOffset = CGSizeMake(0, 0);
	pointView.layer.shadowOpacity = 0.5;
	pointView.layer.shadowRadius = 3;
	
	_timeLabel.sd_layout
		.leftSpaceToView(self,5)
		.centerYEqualToView(self)
		.rightSpaceToView(pointView,5)
		.heightIs(30);
	_timeLabel.text = @"12/03";
	_timeLabel.font = [UIFont systemFontOfSize:13];
	_timeLabel.textAlignment = NSTextAlignmentRight;
	_timeLabel.textColor = [UIColor whiteColor];
	_timeLabel.layer.shadowColor = [UIColor blackColor].CGColor;
	_timeLabel.layer.shadowOffset = CGSizeMake(0, 0);
	_timeLabel.layer.shadowOpacity = 1;
	_timeLabel.layer.shadowRadius = 3;

	
	
	_textContentView.sd_layout
		.leftSpaceToView(pointView,10)
		.topSpaceToView(self,10)
		.bottomSpaceToView(self,10)
		.rightSpaceToView(self,10);
	_textContentView.layer.cornerRadius = 10;
	_textContentView.layer.masksToBounds = YES;
	
	_titleLabel.sd_layout
		.leftSpaceToView(_textContentView,5)
		.topSpaceToView(_textContentView,5)
		.rightSpaceToView(_textContentView,5)
		.heightIs(20);
	_titleLabel.font = [UIFont systemFontOfSize:19 weight:2];
	_titleLabel.text = @"标题";
	_titleLabel.textColor = [UIColor whiteColor];
	_addressLabel.sd_layout
		.leftSpaceToView(_textContentView,5)
		.topSpaceToView(_titleLabel,1)
		.rightSpaceToView(_textContentView,35)
		.heightIs(15);
	_addressLabel.font = [UIFont systemFontOfSize:13];
	_addressLabel.textColor = [UIColor grayColor];
	_addressLabel.text = @"重庆市永川区红河大道319号赋棠苑525";
	_addressLabel.textColor = [UIColor colorWithRed:0.902 green:0.902 blue:0.902 alpha:1.0];
	
	_weatherImageView.image = [UIImage imageNamed:@"sun"];
	_weatherImageView.sd_layout
		.widthIs(20)
		.heightIs(20)
		.leftSpaceToView(_addressLabel,5)
		.topSpaceToView(_titleLabel,1);
	_contentLabel.sd_layout
		.leftSpaceToView(_textContentView,5)
		.rightSpaceToView(_textContentView,5)
		.bottomSpaceToView(_textContentView,5)
		.topSpaceToView(_addressLabel,1);
	_contentLabel.numberOfLines = 0;
	_contentLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightThin];
	_contentLabel.text = @"空文本";
	_contentLabel.textColor = [UIColor whiteColor];
	NSMutableParagraphStyle * style = [[NSMutableParagraphStyle alloc]init];
	style.lineSpacing = 3;
	NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc]initWithString:_contentLabel.text attributes:@{NSParagraphStyleAttributeName:style}];
	_contentLabel.attributedText = attributedString;
	
}

-(void)longpress:(UILongPressGestureRecognizer *)gesture{
	if (gesture.state == UIGestureRecognizerStateBegan) {
		if (_longpressCallback) {
			_longpressCallback(self);
		}
	}
}

#pragma mark setter 


@end
